home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-21 | 1.8 KB | 76 lines | [TEXT/MPS ] |
- (*
- Rot13(string) -- Return the string transformed by Rot13 (for every letter in the string (as opposed to
- number or special character), circularly rotate it through the letters of the alphabet 13 placed).
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w Rot13.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=7868 -sn Main=Rot13 ∂
- Rot13.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
-
- © Copyright 1989 by Apple Computer, Inc.
-
- Initial coding 2/15/89 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S Rot13 } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure Rot13(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- Rot13(paramPtr);
- end;
-
- procedure Rot13(paramPtr: XCmdPtr);
-
- var resultHand: Handle;
- p: Ptr;
- theChar: char;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(Rot13);
- end;
-
- begin
- if paramPtr^.paramCount <> 1 then Fail('§§§ parameter count is not 1 §§§');
-
- resultHand := paramPtr^.params[1]; { First parameter is the string to be rotated. }
-
- { If there's anything in the "previous" string, copy it. }
- if resultHand <> NIL then
- begin
- if HandToHand(resultHand) <> noErr then Fail('§§§ HandToHand failed §§§');
- { Cycle through the text. }
- p := resultHand^;
- while p^ <> 0 do
- begin
- theChar := chr(p^);
- { If this char is rotable, rot it... }
- if theChar in ['A'..'M','a'..'m'] then p^ := p^ + 13
- else if theChar in ['N'..'Z','n'..'z'] then p^ := p^ - 13;
- p := Ptr(ord4(p)+1);
- end;
- end;
-
- { Return the handle. }
- paramPtr^.returnValue := resultHand;
- end;
-
- end.
-